package brave;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;

public class ChatListener implements Listener
{
	@EventHandler
	public void onPlayerChat(PlayerChatEvent event)
	{
		event.setCancelled(true);
		WallPlayer wallPlayer = Brave.getWallPlayer(event.getPlayer());
		
		if (wallPlayer.getState() != WallPlayerState.IN_GAME)
		{
			for(WallPlayer player : Brave.getWallPlayerList())
			{
				if (player.getState() != WallPlayerState.IN_GAME)
				{
					player.getBukkitPlayer().sendMessage("(" + wallPlayer.getName() + "): " + event.getMessage());
				}
			}
		}
		else
		{
			WallTeam myTeam = Brave.getWallGame(wallPlayer.getGameId()).getTeam(wallPlayer.getTeamId());
			myTeam.dispTeamChat(wallPlayer.getName() + ": " + event.getMessage());
		}
	}
}
